#!/bin/bash

echo 'Generating CLI v2 documentation...'

# Get the directory of the script
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

# Define the output file path relative to the script's location
OUTPUT_FILE="$SCRIPT_DIR/../docs/cli_v2.md"

# Ensure the output directory exists
mkdir -p "$(dirname "$OUTPUT_FILE")"

# Write the static content to the output file
cat << EOF > "$OUTPUT_FILE"
# CLI v2 Documentation

The current version of Infinity uses the following arguments in its CLI:
\`\`\`bash
\$ infinity_emb v2 --help
\`\`\`

\`\`\`
EOF

# Append the help output to the file, setting COLUMNS=80 only for this command
TERMINAL_WIDTH=120 infinity_emb v2 --help >> "$OUTPUT_FILE" 2>&1

# Close the code block in the markdown file
echo '```' >> "$OUTPUT_FILE"
echo 'Note: This doc is auto-generated. Do not edit this file directly.' >> "$OUTPUT_FILE"

echo "CLI v2 documentation generated and saved to $OUTPUT_FILE."